﻿using PosClient.Interfaces;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace PosClient.Service
{
    public class ToolService
    {
        public static T ReflectionProGrom<T>(string Path)
        {
            Assembly assembly = Assembly.GetExecutingAssembly(); // 获取当前程序集 
            T action = (T)assembly.CreateInstance("PosClient." + Path);
            return action;
        }

        public static Image GetPictureImage(string Url)
        {
            WebRequest webreq = WebRequest.Create(Url);
            WebResponse webres = webreq.GetResponse();
            using (Stream stream = webres.GetResponseStream())
            {
                return Image.FromStream(stream);
            }
        }
        public static object DeepCopy(object _object)
        {
            if (_object == null) return _object;
            Type T = _object.GetType();
            object o = Activator.CreateInstance(T);
            PropertyInfo[] PI = T.GetProperties();
            for (int i = 0; i < PI.Length; i++)
            {
                PropertyInfo P = PI[i];
                P.SetValue(o, P.GetValue(_object));
            }
            return o;
        }
    }
}
